Overview
Thefetch_dhan_data.py script retrieves comprehensive market data for all NSE equity stocks (approximately 2,775 securities) in a single API call. This is the first script in the EDL Pipeline and creates the foundation for all subsequent data fetching operations.
Purpose
Fetches real-time market metrics including:- Market cap, price, and valuation ratios (P/E, P/B, ROE, ROCE)
- Technical indicators (SMA, RSI, Moving Averages)
- Ownership data (Promoter holding, FII/DII percentages)
- Fundamental metrics (Revenue, Profit Margins, EPS)
- Security identifiers (ISIN, Symbol, Sid)
API Endpoint
https://ow-scanx-analytics.dhan.co/customscan/fetchdtPOSTRequest Payload
Parameters
Field to sort results by (Market Cap)
Sort order (
desc or asc)Maximum number of records to fetch. Set to 5000 to ensure all ~2,775 stocks are returned in one call.
Page number for pagination
List of fields to retrieve (see code example for full list)
Filter parameters:
{"field": "OgInst", "op": "", "val": "ES"}- Equity Segment{"field": "Exch", "op": "", "val": "NSE"}- NSE Exchange
Output Files
Raw API response containing all market data for ~2,775 stocks. Each object includes fields like
Sym, Isin, Mcap, Pe, Ltp, Volume, Sid, etc.Normalized mapping file used by all downstream scripts. Contains:
Symbol- Stock symbol (e.g., “RELIANCE”)ISIN- International Securities Identification NumberName- Display nameSid- Security ID required for OHLCV and indicator APIsFnoFlag- F&O eligibility flag (1 = Yes, 0 = No)
Function Signature
Dependencies
requests- HTTP clientjson- JSON processingos- File path operations
pipeline_utils.get_headers()- Returns standard API headers with rotating User-Agent
None - This is the first script in the pipeline
Code Example
Usage
Performance
- Execution Time: ~3-5 seconds
- API Calls: 1 request
- Output Size: ~5-8 MB (dhan_data_response.json)
- Concurrency: Not applicable (single request)
Notes
- Returns all ~2,775 NSE equity stocks in a single API call
- No pagination required due to high
count: 5000parameter master_isin_map.jsonis used by all subsequent fetching scripts- The
Sidfield is critical for OHLCV and advanced indicator APIs